/* 
 * 创建日期 2011-7-6
 *
 * 成都天和软件公司
 * 电话：028-85425861 
 * 传真：028-85425861-8008 
 * 邮编：610041 
 * 地址：成都市武侯区航空路6号丰德万瑞中心B座1001 
 * 版权所有
 */
package  org.fantasy.cpp.core.html.edit;

import net.sf.json.JSONObject;

import  org.fantasy.common.util.StringUtil;

/**
 * EasyUI验证解析
 * 
 * @author 王文成
 * @version 1.0
 * @since 2011-7-6
 */
public class Validate {

	private boolean required = false;

	private int minlength = 0;

	private int maxlength = Integer.MAX_VALUE;

	private boolean email = false;

	private boolean digit = false;

	private int min = 0;

	private int max = Integer.MAX_VALUE;

	private String json;

	public Validate(String json) {
		this.json = json;
		if (StringUtil.isValid(json)) {
			JSONObject validate = JSONObject.fromObject(json);
			if (validate.containsKey("required")) {
				required = "true".equalsIgnoreCase(validate.getString("required"));
			}
			if (validate.containsKey("digit")) {
				digit = "true".equalsIgnoreCase(validate.getString("digit"));
			}
			if (validate.containsKey("email")) {
				email = "true".equalsIgnoreCase(validate.getString("email"));
			}
			if (validate.containsKey("minlength")) {
				minlength = validate.getInt("minlength");
			}
			if (validate.containsKey("maxlength")) {
				maxlength = validate.getInt("maxlength");
			}
		}
	}

	public boolean isRequired() {
		return required;
	}

	public int getMinlength() {
		return minlength;
	}

	public int getMaxlength() {
		return maxlength;
	}

	public boolean isEmail() {
		return email;
	}

	public boolean isDigit() {
		return digit;
	}

	public int getMin() {
		return min;
	}

	public int getMax() {
		return max;
	}

	@Override
	public String toString() {
		return json.toString();
	}
}
